package com.tanhua.server.service;

import com.alibaba.dubbo.config.annotation.Reference;
import com.tanhua.dubbo.server.api.RecommendUserApi;
import com.tanhua.dubbo.server.pojo.RecommendUser;
import com.tanhua.dubbo.server.vo.PageInfo;
import com.tanhua.server.vo.TodayBest;
import org.springframework.stereotype.Service;


//dubbo远程调用获取接口获取今日佳人信息
@Service
public class RecommendUserService {

    @Reference(version = "1.0.0")
    private RecommendUserApi recommendUserApi;


    /**
     * 根据用户id获取半封装的佳人id和缘分值
     * @param id
     * @return TodayBest
     */
    public TodayBest queryTodayBest(Long id) {

        //获取到推荐佳人的id和得分
        RecommendUser recommendUser = recommendUserApi.queryWithMaxScore(id);
        //非空判断
        if (recommendUser != null) {
            //创建佳人信息对象
            TodayBest todayBest = new TodayBest();
            todayBest.setId(recommendUser.getUserId());

            //取整后封装到todayBest对象中
            //floor向下取整   ceil向上取整
            double score = Math.floor(recommendUser.getScore());
            todayBest.setFateValue(Double.valueOf(score).longValue());
            //返回todayBest
            return todayBest;
        }
        return null;
    }


    public PageInfo<RecommendUser> queryRecommendUserList(Long id, Integer page, Integer pagesize) {
        return recommendUserApi.queryPageInfo(id, page, pagesize);
    }


    /**
     *  查询好友的缘分值
     * @param userId 佳人id
     * @param toUserId  当前用户id
     * @return
     */
    public double queryScore(Long userId, Long toUserId) {
        return recommendUserApi.queryScore(userId,toUserId);
    }
}
